﻿using MediatR;
using S.Authorization.API.Application.Command.RoleMenuCommand;
using S.Authorization.Infrastructure.Interface.RoleMenu;

namespace S.Authorization.API.Application.CommandHandlers.RoleMenuCommandHandler
{
    /// <summary>
    /// 设置角色的权限
    /// 批量添加角色菜单功能表
    /// </summary>
    /// <returns></returns>
    public class RoleMenuAddRangeCommandHandler : IRequestHandler<RoleMenuAddRangeCommand, int>
    {
        #region 注入
        private readonly IRoleMenuRepository repository;
        public RoleMenuAddRangeCommandHandler(IRoleMenuRepository repository)
        {
            this.repository = repository;
        }

        #endregion

        /// <summary>
        /// 设置角色的权限
        /// 批量添加角色菜单功能表
        /// </summary>
        /// <returns></returns>
        public async Task<int> Handle(RoleMenuAddRangeCommand request, CancellationToken cancellationToken)
        {
            return await repository.AddRangeRoleMenuAsync(request.FeatureMenuRoleList);
        }
    }
}
